package com.hyb.controller;


import com.alibaba.fastjson.JSON;
import com.hyb.entity.Plan;
import com.hyb.response.Result;
import com.hyb.service.PlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  销售计划Controller
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@RestController
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    private PlanService planService;

    @RequestMapping(value = "/createPlan",method = RequestMethod.POST)
    @ApiOperation("制定销售计划")
    public String createPlan(@RequestBody Plan plan){
        planService.createPlan(plan);
        return JSON.toJSONString(new Result().setCode(200).setMessage("保存成功"));
    }

    @RequestMapping(value = "/loadPlansBySaleId",method = RequestMethod.GET)
    @ApiOperation("通过销售机会Id获取销售计划")
    public String loadPlansBySaleId(Integer saleId){
        List<Plan> plansBySaleId = planService.getPlansBySaleId(saleId);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(plansBySaleId));
    }

    @RequestMapping(value = "/loadNotNullPlanResultBySaleId",method = RequestMethod.GET)
    @ApiOperation("根据销售机会Id获取计划内容不为空的计划")
    public String loadNotNullPlanResultBySaleId(Integer saleId){
        List<Plan> notNullPlanResultBySaleId = planService.getNotNullPlanResultBySaleId(saleId);
        return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(notNullPlanResultBySaleId));
    }

   @RequestMapping(value = "/loadIsNullPlanResultBySaleId",method = RequestMethod.GET)
   @ApiOperation("根据销售机会Id获取计划内容为空的计划")
    public String loadIsNullPlanResultBySaleId(Integer saleId){
       List<Plan> isNullPlanResultBySaleId = planService.getIsNullPlanResultBySaleId(saleId);
       return JSON.toJSONString(new Result().setCode(200).setMessage("加载成功").setData(isNullPlanResultBySaleId));
   }

   @RequestMapping(value = "/savePlanResult",method = RequestMethod.PUT)
   @ApiOperation("保存开发计划的结果")
   public String savePlanResult(@RequestBody Plan plan){
        planService.updatePlanResult(plan);
        return JSON.toJSONString(new Result().setCode(200).setMessage("保存成功"));
   }

}
